package logic.SysOrganization

import cn.ibizlab.util.domain.EntityBase
import cn.ibizlab.util.helper.RuleUtils
import cn.ibizlab.util.security.AuthenticationUser
import cn.ibizlab.util.security.SpringContextHolder
import cn.ibizlab.core.ad.domain.SysOrganization
import cn.ibizlab.core.ad.service.SysOrganizationService
import cn.ibizlab.core.ad.domain.SysOrganization
import cn.ibizlab.core.ad.service.SysOrganizationService
import cn.ibizlab.core.ad.domain.SysOrganization
import cn.ibizlab.core.ad.service.SysOrganizationService
import cn.ibizlab.core.ad.domain.SysOrganization
import cn.ibizlab.core.ad.service.SysOrganizationService
import com.alibaba.fastjson.JSONObject
import org.springframework.util.ObjectUtils

/**
 *  获取单位清单（根据id或用户身份）_bk
 */
class ItemsBk {

    //当前用户
    def curuser = AuthenticationUser.getAuthenticationUser()
    //传入变量
    def _default
    def _filter = new EntityBase()
    //filterOrg
    def _filterorg = new SysOrganization()
    //item
    def _item = new SysOrganization()
    //list
    def _list = new SysOrganization()
    def _realid = new EntityBase()
    //返回参数
    def _return

    def execute(arg) {
        println 'running....'
        _default = arg
        
        
        
        _return = arg
        begin()
        println 'running end....'
        return _return
    }

    //开始
    def begin() {
    
        //id不为空
        if(((RuleUtils.test(_default.get('id'), 'ISNOTNULL', 'null')))) {
            deaction1()
        }
        //id为空按用户身份获取
        if(((RuleUtils.test(_default.get('id'), 'ISNULL', 'null')))) {
            prepareparam3()
        }
    }

    //校验获取真实id
    def deaction1() {
        SpringContextHolder.getBean(SysOrganizationService.class).findOrganizationId(_default)

        if(true) {
            prepareparam1()
        }
    }

    //准备参数
    def prepareparam1() {
        _default.set("id", _realid.get(""))
        _filterorg.set("n_parent_id_eq", _realid.get(""))
        _filterorg.set("size", "10000")

        if(true) {
            dedataquery1()
        }
    }

    //准备参数
    def prepareparam3() {
        _filterorg.set("size", "10000")

        if(true) {
            dedataquery2()
        }
    }

    //查询下级节点
    def dedataquery1() {
        //DEDataQuery 暂未实现
        if(true) {
            deaction2()
        }
    }

    //查询我的单位集合
    def dedataquery2() {
        //DEDataQuery 暂未实现
        //连接名称
        if(true) {
            loopsubcall1()
        }
        //连接名称
        else if(true) {
            end1()
        }
    }

    //循环子调用
    def loopsubcall1() {
    //未支持的处理节点

        if(true) {
            prepareparam4()
        }
    }

    //查询上级节点
    def deaction2() {
        SpringContextHolder.getBean(SysOrganizationService.class).get(_default)

        if(true) {
            prepareparam2()
        }
    }

    //清空上级节点
    def prepareparam4() {
        _item.set("parent_id", null)

    }

    //把父节点插入进子节点集合头部
    def prepareparam2() {
        _default.set("parent_id", null)
        _list.set("", _default.get(""))

        if(true) {
            end1()
        }
    }

    //结束
    def end1() {
        _return = _list

    }

}
